const mysql2 = require('mysql2');
const config = require('./config');

const pool = mysql2.createPool({
  host: config.DATABASE_HOST,
  port: config.DATABASE_PORT,
  user: config.DATABASE_USER,
  password: config.DATABASE_PASSWORD,
  database: config.DATABASE_NAME,
  dateStrings: true
});

// 默认导出 Promise 形式（兼容旧代码）
const promisePool = pool.promise();

module.exports = promisePool;

// 额外导出原始 pool，用于 stream 导出
module.exports.rawPool = pool;
